import axios from "./index";
import { ref, Ref } from "vue"
// 创建方法
const useApi = <T>(url: string, options: object) => {
    // 创建一个ref作为接口返回的接受
    const response: Ref<T | undefined> = ref();
    // 创建接口请求方法
    const request = async () => {
        const res = await axios({
            url: url,
            ...options,
        });

        // 将接口返回的值赋值给response
        response.value = res?.data;
    }
    // 将方法和接受返回的值return
    return {
        response,
        request
    }
}


export default useApi;